#include "SQLDropTableSpaceStatement.h"
#include "SQLDDLStatement.h"
#include "../../visitor/SQLASTVisitor.h"
#include "../SQLName.h"
#include "../../../DbType.h"
#include "../../../utils/instanceof.h"

SQLDropTableSpaceStatement::SQLDropTableSpaceStatement()
{
}

SQLDropTableSpaceStatement::SQLDropTableSpaceStatement(DbType_ptr  dbType) : SQLStatementImpl(dbType)
{
}

void SQLDropTableSpaceStatement::accept0(SQLASTVisitor_ptr visitor)
{
  if (visitor->visit(SharedObject(SQLDropTableSpaceStatement)))
  {
    acceptChild(visitor, name);
  }
  visitor->endVisit(SharedObject(SQLDropTableSpaceStatement));
}

SQLName_ptr SQLDropTableSpaceStatement::getName()
{
  return name;
}

void SQLDropTableSpaceStatement::setName(SQLName_ptr x)
{
  if (x != NULL)
  {
    x->setParent(SharedObject(SQLDropTableSpaceStatement));
  }
  this->name = x;
}

string_ptr  SQLDropTableSpaceStatement::getTableSpaceName()
{
  if (name == NULL)
  {
    return NULL;
  }

  // if (name instanceof SQLName*) {
  return name->getSimpleName();
  // }

  return NULL;
}

SQLExpr_ptr SQLDropTableSpaceStatement::getEngine()
{
  return engine;
}

void SQLDropTableSpaceStatement::setEngine(SQLExpr_ptr x)
{
  if (x != NULL)
  {
    x->setParent(SharedObject(SQLDropTableSpaceStatement));
  }
  this->engine = x;
}

BOOL_ptr SQLDropTableSpaceStatement::isIfExists()
{
  return ifExists;
}

void SQLDropTableSpaceStatement::setIfExists(BOOL_ptr ifExists)
{
  this->ifExists = ifExists;
}

BOOL_ptr SQLDropTableSpaceStatement::replace(SQLExpr_ptr expr, SQLExpr_ptr target)
{
  if (name == expr)
  {
    setName(std::dynamic_pointer_cast<SQLName>(target));
    return BOOL::TRUE;
  }

  return BOOL::FALSE;
}

SQLDDLStatement::DDLObjectType SQLDropTableSpaceStatement::getDDLObjectType()
{
  return SQLDDLStatement::DDLObjectType::TABLE_SPACE;
}
